<% if @project %>
  <% page_title "Deploys" %>
  <%= render 'projects/header', project: @project, tab: "deploys" %>
<% else %>
  <%= page_title "Deploys" %>
<% end %>

<section class="tabs">
  <div class="row">
    <%= search_form do %>
      <div class="col-sm-2">
        <%= label_tag 'Deployer name' %>
        <%= text_field_tag 'search[deployer]', params.dig(:search, :deployer), class: "form-control" %>
      </div>

      <% if @project %>
        <div class="col-sm-2">
          <%= label_tag :git_sha %>
          <%= text_field_tag 'search[git_sha]', params.dig(:search, :git_sha), class: "form-control" %>
        </div>
      <% else %>
        <div class="col-sm-2">
          <%= label_tag :project %>
          <%= text_field_tag 'search[project_name]', params.dig(:search, :project_name), placeholder: 'project name', class: "form-control" %>
        </div>
      <% end %>

      <%= search_select :production, [["Yes", "true"], ["No", "false"]], size: 1 %>
      <%= search_select :code_deployed, [["Yes", "true"], ["No", "false"]], title: "Code deployed?", label: "Code", size: 1 %>
      <%= search_select :status, Job::VALID_STATUSES %>
      <%= search_select :group, Environment.env_deploy_group_array %>
      <%= search_select :time_format, User::TIME_FORMATS, selected: params.dig(:search, :time_format) || current_user.time_format, label: 'Time', size: 1 %>
    <% end %>
  </div>

  <section class="timeline-content clearfix">
    <div class="deploy-csv">
      <%= link_to "Download as CSV", deploys_path(format: "csv", params: params.to_unsafe_h) %>
    </div>
    <%= render "table" %>
  </section>
</section>
